package io.gitee.caoxiaoyu97.log4j.defender.properties;

import java.util.HashMap;
import java.util.Map;

import io.gitee.caoxiaoyu97.log4j.defender.constants.DefenderConstants;
import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = DefenderConstants.CXY_LOG_DEFENDER)
public class DefenderProperties {
    private String type;
    private DefenderKeyProperties regexkey = new DefenderKeyProperties();
    private DefenderKeyProperties regexvalue = new DefenderKeyProperties();
    private DefenderKeyProperties stringfield = new DefenderKeyProperties();
    private DefenderKeyProperties bean = new DefenderKeyProperties();
    private Map<String, String> includepkgs = new HashMap<>();
    private Map<String, String> excludepkgs = new HashMap<>();
    private Integer maxsearchsize = Integer.valueOf(10000);
    private Boolean enable = Boolean.FALSE;

    public String getType() {
        return this.type;
    }

    public void setType(String type) {
        this.type = type;
    }

    protected DefenderKeyProperties getWithDefaultProperties(DefenderKeyProperties origin) {
        return (null == origin) ? new DefenderKeyProperties() : origin;
    }

    protected Map<String, String> getWithDefaultMap(Map<String, String> origin) {
        return (null == origin) ? new HashMap<>(0) : origin;
    }

    public DefenderKeyProperties getRegexkey() {
        return getWithDefaultProperties(this.regexkey);
    }

    public void setRegexkey(DefenderKeyProperties regexkey) {
        this.regexkey = regexkey;
    }

    public DefenderKeyProperties getRegexvalue() {
        return getWithDefaultProperties(this.regexvalue);
    }

    public void setRegexvalue(DefenderKeyProperties regexvalue) {
        this.regexvalue = regexvalue;
    }

    public DefenderKeyProperties getStringfield() {
        return getWithDefaultProperties(this.stringfield);
    }

    public void setStringfield(DefenderKeyProperties stringfield) {
        this.stringfield = stringfield;
    }

    public Map<String, String> getIncludepkgs() {
        return getWithDefaultMap(this.includepkgs);
    }

    public void setIncludepkgs(Map<String, String> includepkgs) {
        this.includepkgs = includepkgs;
    }

    public Map<String, String> getExcludepkgs() {
        return getWithDefaultMap(this.excludepkgs);
    }

    public void setExcludepkgs(Map<String, String> excludepkgs) {
        this.excludepkgs = excludepkgs;
    }

    public DefenderKeyProperties getBean() {
        return getWithDefaultProperties(this.bean);
    }

    public void setBean(DefenderKeyProperties bean) {
        this.bean = bean;
    }

    public Integer getMaxsearchsize() {
        return Integer.valueOf((null == this.maxsearchsize || this.maxsearchsize.intValue() < 0) ? 10000 : this.maxsearchsize
                .intValue());
    }

    public void setMaxsearchsize(Integer maxSearchSize) {
        this.maxsearchsize = maxSearchSize;
    }

    public Boolean getEnable() {
        return (null == this.enable) ? Boolean.FALSE : this.enable;
    }

    public void setEnable(Boolean enable) {
        this.enable = enable;
    }
}
